#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File ：AddressMapper.py
@Author ：zqy
@Email : zqingy@work@163.com 
@note: 
"""
from application.mapper import BaseMapper
from application.model.OrderModel import Address
from application.util.MysqlUtil import mysql_session


class AddressMapper(BaseMapper):
    model: Address = Address

    @classmethod
    def get_by_user_id(cls, user_id):
        return cls.model.query.filter_by(user_id=user_id).all()

    @classmethod
    def update_by_ids(cls, _ids, data):
        try:
            cls.model.query.filter(cls.model.id.in_(_ids)).update(data)
            mysql_session.commit()
            return True
        except Exception:
            mysql_session.rollback()
        return False
